package com.cloudfun.campusshare.configuration.config;

import cn.hutool.core.lang.Snowflake;
import com.cloudfun.campusshare.configuration.property.SnowflakeProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by Huqin on 2020/8/11
 */
@Configuration
@Slf4j
public class SnowflakeConfig {

    @Autowired
    private SnowflakeProperties snowflakeProperties;

    @Bean
    public Snowflake snowflake() {
        log.info("construct Snowflake use workerId: {}, dataCenterId: {}", snowflakeProperties.getWorkerId(), snowflakeProperties.getDataCenterId());
        return new Snowflake(snowflakeProperties.getWorkerId(), snowflakeProperties.getDataCenterId());
    }

}
